﻿namespace HRM.CORE
{
    using DevExpress.Utils;
    using DevExpress.XtraEditors;
    using DevExpress.XtraEditors.Controls;
    using APP.HELPER;
    using HRM.CORE;
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms; using Common;
    using Common;
    using Extra.ERP;

    public class xucSelectEmployees : Common.xucBase
    {
        private SimpleButton bbiSelect;
        private CheckEdit cheMultiSelect;
        private IContainer components;
        private GroupControl gcTitle;
        private DevExpress.Utils.ImageCollection imgList;
        private int m_Status;
        private int m_Type;
        private PanelControl panelControl1;
        private xucListEmployee xucListEmployee1;
        private xucListInsurance xucListInsurance1;

        public event SelectedEventHander Selected;

        public xucSelectEmployees()
        {
            this.components = null;
            this.m_Status = 1;
            this.m_Type = 0;
            this.InitializeComponent();
        }

        public xucSelectEmployees(int Status)
        {
            this.components = null;
            this.m_Status = 1;
            this.m_Type = 0;
            this.InitializeComponent();
            this.m_Status = Status;
            this.Init();
        }

        public xucSelectEmployees(int Status, int Type)
        {
            this.components = null;
            this.m_Status = 1;
            this.m_Type = 0;
            this.InitializeComponent();
            this.m_Status = Status;
            this.m_Type = Type;
            this.Init();
        }

        private void bbiSelect_Click(object sender, EventArgs e)
        {
            DataTable dataTable;
            if (this.m_Type == 0)
            {
                dataTable = this.xucListEmployee1.GetDataTable();
            }
            else
            {
                dataTable = this.xucListInsurance1.GetDataTable();
            }
            if (dataTable.Rows.Count <= 0)
            {
                XtraMessageBox.Show("Vui l\x00f2ng chọn danh s\x00e1ch nh\x00e2n vi\x00ean để ph\x00e1t sinh dữ liệu!", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
            }
            else
            {
                this.RaiseSelectedEventHander(dataTable);
            }
        }

        private void cheMultiSelect_CheckedChanged(object sender, EventArgs e)
        {
            if (this.cheMultiSelect.Checked)
            {
                if (this.m_Type == 0)
                {
                    this.xucListEmployee1.ListSelectionMode(SelectionMode.MultiSimple);
                }
                else
                {
                    this.xucListInsurance1.ListSelectionMode(SelectionMode.MultiSimple);
                }
            }
            else if (this.m_Type == 0)
            {
                this.xucListEmployee1.ListSelectionMode(SelectionMode.One);
            }
            else
            {
                this.xucListInsurance1.ListSelectionMode(SelectionMode.One);
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void Init()
        {
            if (this.m_Type == 0)
            {
                if (this.xucListEmployee1 == null)
                {
                    this.xucListEmployee1 = new xucListEmployee();
                    this.xucListEmployee1.ListSelectionMode(SelectionMode.MultiSimple);
                    this.xucListEmployee1.Dock = DockStyle.Fill;
                    base.Controls.Add(this.xucListEmployee1);
                    this.xucListEmployee1.BringToFront();
                }
            }
            else if (this.xucListInsurance1 == null)
            {
                this.xucListInsurance1 = new xucListInsurance();
                this.xucListInsurance1.ListSelectionMode(SelectionMode.MultiSimple);
                this.xucListInsurance1.Dock = DockStyle.Fill;
                base.Controls.Add(this.xucListInsurance1);
                this.xucListInsurance1.BringToFront();
            }
            this.LoadData();
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            ComponentResourceManager manager = new ComponentResourceManager(typeof(xucSelectEmployees));
            this.imgList = new DevExpress.Utils.ImageCollection(this.components);
            this.panelControl1 = new PanelControl();
            this.cheMultiSelect = new CheckEdit();
            this.bbiSelect = new SimpleButton();
            this.gcTitle = new GroupControl();
            this.imgList.BeginInit();
            this.panelControl1.BeginInit();
            this.panelControl1.SuspendLayout();
            this.cheMultiSelect.Properties.BeginInit();
            this.gcTitle.BeginInit();
            base.SuspendLayout();
            this.imgList.ImageStream = (ImageCollectionStreamer) manager.GetObject("imgList.ImageStream");
            this.imgList.Images.SetKeyName(0, "male.png");
            this.imgList.Images.SetKeyName(1, "user_woman.png");
            this.imgList.Images.SetKeyName(2, "close.png");
            this.imgList.Images.SetKeyName(3, "document_small_upload.png");
            this.panelControl1.BorderStyle = BorderStyles.NoBorder;
            this.panelControl1.Controls.Add(this.cheMultiSelect);
            this.panelControl1.Controls.Add(this.bbiSelect);
            this.panelControl1.Dock = DockStyle.Bottom;
            this.panelControl1.Location = new Point(0, 0x1b3);
            this.panelControl1.Name = "panelControl1";
            this.panelControl1.Size = new Size(210, 0x29);
            this.panelControl1.TabIndex = 5;
            this.cheMultiSelect.EditValue = true;
            this.cheMultiSelect.Location = new Point(3, 10);
            this.cheMultiSelect.Name = "cheMultiSelect";
            this.cheMultiSelect.Properties.Caption = "Chọn nhiều d\x00f2ng";
            this.cheMultiSelect.Size = new Size(0x69, 0x13);
            this.cheMultiSelect.TabIndex = 7;
            this.cheMultiSelect.CheckedChanged += new EventHandler(this.cheMultiSelect_CheckedChanged);
            this.bbiSelect.Anchor = AnchorStyles.Right | AnchorStyles.Top;
            this.bbiSelect.ImageIndex = 3;
            this.bbiSelect.ImageList = this.imgList;
            this.bbiSelect.Location = new Point(0x6f, 9);
            this.bbiSelect.Name = "bbiSelect";
            this.bbiSelect.Size = new Size(90, 0x17);
            this.bbiSelect.TabIndex = 1;
            this.bbiSelect.Text = "Th\x00eam";
            this.bbiSelect.Click += new EventHandler(this.bbiSelect_Click);
            this.gcTitle.Dock = DockStyle.Top;
            this.gcTitle.Location = new Point(0, 0);
            this.gcTitle.Name = "gcTitle";
            this.gcTitle.Size = new Size(210, 0x16);
            this.gcTitle.TabIndex = 6;
            this.gcTitle.Text = "Chọn Nh\x00e2n Vi\x00ean";
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.Controls.Add(this.gcTitle);
            base.Controls.Add(this.panelControl1);
            base.Name = "xucSelectEmployees";
            base.Size = new Size(210, 0x1dc);
            this.imgList.EndInit();
            this.panelControl1.EndInit();
            this.panelControl1.ResumeLayout(false);
            this.cheMultiSelect.Properties.EndInit();
            this.gcTitle.EndInit();
            base.ResumeLayout(false);
        }

        public void LoadData()
        {
            if (this.m_Type == 0)
            {
                if (this.xucListEmployee1 != null)
                {
                    this.xucListEmployee1.LoadData(this.m_Status, MyLogin.Level, MyLogin.Code, DateTime.Now, DateTime.Now);
                }
            }
            else if (this.xucListInsurance1 != null)
            {
                this.xucListInsurance1.LoadData(this.m_Status);
            }
        }

        public void LoadData(int Status)
        {
            this.m_Status = Status;
            this.Init();
        }

        public void LoadData(int Status, int Type)
        {
            this.m_Status = Status;
            this.m_Type = Type;
            this.Init();
        }

        public void RaiseSelectedEventHander(DataTable Table)
        {
            if (this.Selected != null)
            {
                this.Selected(this, Table);
            }
        }

        public void SetTitle(string Title, string ButtonText)
        {
            this.gcTitle.Text = Title;
            this.bbiSelect.Text = ButtonText;
        }

        public delegate void SelectedEventHander(object sender, DataTable Table);
    }
}

